package com.example.task1.ui.AllService.life;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.LifeNewsListBean;
import com.example.task1.ui.BaseAdapter;
import com.example.task1.ui.base.NewsDetailsActivity;

import java.util.ArrayList;
import java.util.List;

public class LifeNewsListAdapter extends BaseAdapter<LifeNewsListBean.RowsDTO> {

    private List<LifeNewsListBean.RowsDTO> mData = new ArrayList<>();
    private Context context;
    private ImageView image;
    private TextView tvName;
    private TextView tvContent;
    private TextView tvReadNum;
    private TextView tvLikeNum;

    public LifeNewsListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<LifeNewsListBean.RowsDTO> rows) {
        int size = mData.size();
        mData.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.lifenewslist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<LifeNewsListBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, LifeNewsListBean.RowsDTO date) {
        MyApplication.glide(image, date.getCover());
        tvName.setText(date.getTitle());
        tvContent.setText(Html.fromHtml(date.getContent()));
        tvLikeNum.setText(date.getLikeNum() + "人赞");
        tvReadNum.setText(date.getLikeNum() + "人阅读");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, NewsDetailsActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View view) {
        image = (ImageView) view.findViewById(R.id.image);
        tvName = (TextView) view.findViewById(R.id.tv_name);
        tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvReadNum = (TextView) view.findViewById(R.id.tv_readNum);
        tvLikeNum = (TextView) view.findViewById(R.id.tv_likeNum);
    }
}
